package org.xlx.xlx_oa.reimburse.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.xlx.xlx_oa.common.ResponseBean;
import org.xlx.xlx_oa.reimburse.api.ReimburseApi;
import org.xlx.xlx_oa.reimburse.domain.vo.ReimburseVo;
import org.xlx.xlx_oa.reimburse.service.ReimburseService;
import org.xlx.xlx_oa.role_user.domain.vo.AuditVo;

@RestController
@RequestMapping("/v1/reimburse")
public class ReimburseController implements ReimburseApi {
    @Autowired
    private ReimburseService reimburseService;

    @PostMapping("/upload")
    @Override
    public ResponseBean uploadImage(@RequestPart("files") MultipartFile[] files){
        try {
            return ResponseBean.successFactory(reimburseService.uploadImage(files));
        } catch (Exception e) {
            return ResponseBean.failureFactory(e.getMessage());
        }
    }

    @PostMapping("/save")
    @Override
    public ResponseBean saveApply(@RequestBody ReimburseVo reimburseVo) {
        return ResponseBean.successFactory(reimburseService.saveReimburse(reimburseVo));
    }

    @PostMapping("/beAudit/list")
    @Override
    public ResponseBean getBeAuditList(@RequestBody ReimburseVo reimburseVo) {
        return ResponseBean.successFactory(reimburseService.getBeAuditList(reimburseVo));
    }

    @PostMapping("/beAudit/count")
    @Override
    public ResponseBean getBeAuditCount(@RequestBody ReimburseVo reimburseVo) {
        return ResponseBean.successFactory(reimburseService.getBeAuditedCount(reimburseVo));
    }

    @PostMapping("/apply/list")
    @Override
    public ResponseBean getApplyList(@RequestBody ReimburseVo reimburseVo) {
        return ResponseBean.successFactory(reimburseService.getApplyList(reimburseVo));
    }

    @PostMapping("/apply/count")
    @Override
    public ResponseBean getApplyCount(@RequestBody ReimburseVo reimburseVo) {
        return ResponseBean.successFactory(reimburseService.getApplyCount(reimburseVo));
    }

    @GetMapping("/detail/{id}")
    @Override
    public ResponseBean getApplyDetail(@PathVariable(value = "id") Long id) {
        return ResponseBean.successFactory(reimburseService.getApplyDetail(id));
    }

    @PostMapping("/audit")
    @Override
    public ResponseBean audit(@RequestBody AuditVo auditVo) {
        return ResponseBean.successFactory(reimburseService.auditApply(auditVo));
    }

}

